package com.example.hospitallogin.modules.login.controller;

import com.example.hospitallogin.assembly.BaseResponse;
import com.example.hospitallogin.assembly.CustomResultCode;
import com.example.hospitallogin.assembly.ResultCode;
import com.example.hospitallogin.modules.login.bff.LoginImpl;
import com.example.hospitallogin.modules.login.dto.DoctorLoginReq;
import com.example.hospitallogin.modules.login.dto.HospitalLoginReq;
import com.example.hospitallogin.modules.login.dto.UserLoginReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author qiancheng@cqxyy.net
 * @date 2022/9/15
 */
@RestController
@RequestMapping("/login")
@Api(tags = "登录接口")
@Validated
public class LoginController {

    @Autowired
    private LoginImpl login;


    @ApiOperation(value = "用户登录")
    @RequestMapping(path = "/user-login",method = RequestMethod.POST)
    public BaseResponse userLogin(@RequestBody @Valid UserLoginReq req){
        Object result = login.userLogin(req);
        if(result instanceof String){
            return BaseResponse.fail(ResultCode.LOGINERROR);
        }
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "医院登录")
    @RequestMapping(path = "/hospital-login",method = RequestMethod.POST)
    public BaseResponse hospitalLogin(@RequestBody @Valid HospitalLoginReq req){
        Object object = login.hospitalLogin(req);
        if(object instanceof String){
            return BaseResponse.fail(CustomResultCode.LOGINERROR,(String)object);
        }
        return BaseResponse.success(object);
    };

    @ApiOperation(value = "医生登录")
    @RequestMapping(path = "/doctor-login",method = RequestMethod.POST)
    public BaseResponse doctorLogin(@RequestBody @Valid DoctorLoginReq req){
        Object object = login.doctorLogin(req);
        if(object instanceof String){
            return BaseResponse.fail(CustomResultCode.LOGINERROR,(String)object);
        }
        return BaseResponse.success(object);
    };
}
